<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;
use app\common\builder\TableBuilder;
use app\common\builder\TableFront;
use think\facade\View;
use think\response\Json;
use app\common\model\Bank;

class OrderInvoice extends Base
{
    //主键
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\OrderInvoice';

    protected $hasOne = ['user', 'business', 'orders'];

    protected $append = ['status_name'];

    public function index()
    {
        return $this->setTable();
    }

    //自动构建table,按需修改
    public function setTable()
    {
        $tableFront = TableFront::getInstance()
            ->addRow(['type' => 'checkbox', 'fixed' => 'left', 'title' => '全选'])
            ->addRow(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 60])
            ->addRow(['field' => 'user_code', 'title' => '申请会员', 'templet' => '<div>{{d.user.account}}</div>'])
            ->addRow(['field' => 'business', 'title' => '商家名称', 'templet' => '<div>{{d.business.title}}</div>'])
            ->addRow(['field' => 'order_sn', 'title' => '订单号', 'templet' => '<div>{{d.orders.sn}}</div>'])
            ->addRow(['field' => 'type', 'title' => '发票类型', 'templet' => '<div>{{d.type == 1?"个人":"企业"}}</div>'])
            ->addRow(['field' => 'title', 'title' => '抬头', 'width' => 120])
            ->addRow(['field' => 'tax_no', 'title' => '税号', 'width' => 150])
            ->addRow(['field' => 'amount', 'title' => '开票金额'])
            ->addRow(['field' => 'cate', 'title' => '类别', 'width' => 100, 'templet' => '<div>{{d.type == 1?"电子发票":"纸质发票"}}</div>'])
            ->addRow(['field' => 'email', 'title' => '邮箱地址', 'width' => 110])
            ->addRow(['field' => 'receiver', 'title' => '收件人'])
            ->addRow(['field' => 'mobile', 'title' => '收件人手机号'])
            ->addRow(['field' => 'address', 'title' => '收件地址'])
            ->addRow(['field' => 'create_time', 'title' => '申请时间', 'width' => 150])
            ->addRow(['field' => 'audit_time', 'title' => '审核时间', 'width' => 150])
            ->addRow(['field' => 'status_name', 'title' => '状态'])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#rightBtn', 'title' => '操作', 'width' => 80]);

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->addRightButtons(['edit' => ['title' => '开票', 'width' => 1920, 'height' => 1080]])
            ->setSearch($this->setSearch())
            ->addExtraHtml(['OrderInvoice'])
            ->fetch();
    }

    //自动构建Search，按需修改
    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['uid', '会员编号/用户名/手机号', 'input', '', '\app\common\model\User', 'code|account|mobile,id'])
            ->setSearch(['title', '抬头', 'input', '', '', '', 'like'])
            ->setSearch(['status', '状态', 'select', [1 => '申请中', 2 => '已开票', 3 => '已驳回']]);

    }

    public function edit($name = '', $id = '', $tpl = 'order_invoice/edit', $info = '')
    {
        return parent::edit($name, $id, $tpl, $info); // TODO: Change the autogenerated stub
    }

    public function save($param = [], $model = true): Json
    {
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }


}
